import * as Cesium from 'cesium';

class SpaceGridClass {
  constructor(viewer) {
    this.defaultPos = [117.1213838888, 40.1407018888, 0]
    this.viewer = viewer;
    this.lineEntitiesLv0 = []
    this.lineEntitiesLv1 = []
    this.lineEntitiesLv2 = []
    this.lineEntitiesLv3 = []
    this.lineEntitiesLv4 = []
    this.lineEntitiesLv5 = []
    this.lineEntitiesLv6 = []
    this.lineEntitiesLv7 = []
    this.lineEntitiesLv8 = []
    this.lineEntitiesLv9 = []
    this.lineEntitiesLv10 = []
    this.lineEntitiesLv11 = []
    this.lineEntitiesLv12 = []
    this.lineEntitiesLv13 = []
    this.lineEntitiesLv14 = []
    this.lineEntitiesLv15 = []
    this.lineEntitiesLv16 = []
    this.lineEntitiesLv17 = []
    this.lineEntitiesLv18 = []
    this.lineEntitiesLv19 = []
    this.lineEntitiesLv20 = []
    this.lineLvArr = [
      this.lineEntitiesLv0,
      this.lineEntitiesLv1,
      this.lineEntitiesLv2,
      this.lineEntitiesLv3,
      this.lineEntitiesLv4,
      this.lineEntitiesLv5,
      this.lineEntitiesLv6,
    ]
    this.mapCfg = {
      0: [[[-180, 180, -66, 66]], 500000, [120, 66, 1], [3, 2, 500000], [3, 2, 500000]],
      1: [[[0, 180, 0, 66]], 100000, [180, 66, 1], [1, 1, 100000], [1, 1, 100000]],
      2: [[[90, 180, 0, 66]], 50000, [300, 330, 1], [0.3, 0.2, 50000], [0.3, 0.2, 50000]],
      3: [[[90, 135, 22, 44]], 10000, [90, 44, 1], [0.5, 0.5, 10000], [0.5, 0.5, 10000]],
      4: [[[105, 120, 38.5, 44]], 5000, [[4, 3, 1], [9, 5.5, 5000], [0.01, 0.01, 5000]]],
      5: [[[115, 120, 38.5, 44], [117, 126, 38.5, 44]], 2000, [[4, 4, 1], [1.8, 1.1, 2000], [0.003, 0.003, 2000]]],
    }
    this.positionsYLineArr = []
    this.positionsLonLLA = []
    this.positionsLatLLA = []
    this.initHeight = 500000
    this.Level = 0
  }
  // 添加经线
  _countLonGrid () {
    let positionsXJson = {}
    let positionsXLineArr = []
    let strll = ''
    for (let y = -90; y <= 90; y += 30) {
      let positionsX = [];
      strll = `x:-180_180,y:${y}`
      for (let x = -180; x <= 180; x += 30) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        positionsXJson[`${x}_${y}`] = pos
        positionsX.push(pos)
      }
      positionsX.push(positionsX[0])
      positionsXLineArr.push(positionsX)
      this.lineEntitiesLv0.push(this.viewer.entities.add(
        {
          name: strll,
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  // 添加纬线
  _countLatGrid () {
    let positionsYJson = {}
    this.positionsYLineArr = []
    this.positionsLonLLA = []
    let strll = ''
    for (let x = -180; x <= 180; x += 30) {
      let positionsY = [];
      let positionsZ = [];
      strll = `x:${x},y:-90_90`
      for (let y = -90; y <= 90; y += 30) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        positionsYJson[`${x}_${y}`] = pos
        positionsY.push(pos)
        const posHeight = Cesium.Cartesian3.fromDegrees(x, y, this.initHeight)
        positionsZ.push(posHeight)
      }
      this.positionsLonLLA.push(positionsZ)
      this.positionsYLineArr.push(positionsY)
      this.lineEntitiesLv0.push(this.viewer.entities.add(
        {
          name: strll,
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  // 添加高程线
  _countAltGrid () {
    this.positionsLonLLA.forEach((element, lonIndex) => {
      element.forEach((ipos, latIndex) => {
        this.lineEntitiesLv0.push(this.viewer.entities.add(
          {
            name: `${lonIndex}-${latIndex}`,
            polyline: {
              positions: [this.positionsYLineArr[lonIndex][latIndex], ipos],
              width: 1,
              material: Cesium.Color.RED
            }
          }
        ))
      });
      this.lineEntitiesLv0.push(this.viewer.entities.add(
        {
          name: `top-${lonIndex}`,
          class: `lon-line-level-01`,
          polyline: {
            positions: element,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    });
    for (let index = 0; index < 132 / 2; index++) {
      this.positionsLatLLA[index] = []
      let pos = []
      this.positionsLonLLA.forEach(element => {
        pos.push(element[index])
      });
      pos.push(pos[0])
      this.lineEntitiesLv0.push(this.viewer.entities.add(
        {
          name: `top-${index}`,
          class: `lat-line-level-01`,
          polyline: {
            positions: pos,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
      this.positionsLatLLA[index].push(pos)
    }
    // console.log('this.lineEntitiesLv0->', this.lineEntitiesLv0);
  }
  // 判断所属区域
  _getGridIndex (pos) {
    // const lv2LonArr = Array.from({ length: (180 / 3) }, (_, i) => `${i + 1}`.padStart(2, '0'));
    // const lv2latArr = Array.from({ length: (66 / 2) }, (_, i) => `${i + 1}`.padStart(2, '0'));
    // console.log(lv2LonArr, lv2latArr);
    let hime = `${pos[0] > 0 ? 'E' : 'W'}${pos[1] > 0 ? 'N' : 'S'}`
    let posLonIndex = `${Math.ceil(Math.abs(pos[0]) / 3)}`.padStart(2, '0')
    let posLatIndex = `${Math.ceil(Math.abs(pos[1]) / 2)}`.padStart(2, '0')
    if (pos[0] === 0) {
      posLonIndex = '01'
    }
    if (pos[1] === 0) {
      posLatIndex = '01'
    }
    return `${hime}${posLonIndex}${posLatIndex}`
  }
  // 经度相当于Y值(176和-176)
  // { x: -2595162.244266044, y: 181471.42221769065, z: -5803947.557601775 }
  // { x: -2595162.244266044, y: -181471.42221769065, z: -5803947.557601775 }
  // 纬度相当于Z值(60和-60)
  // {"x": -3189316.6008361154,"y": 223018.74217498366,"z": 5500477.1339386385}
  // {"x": -3189316.6008361154,"y": 223018.74217498366,"z": -5500477.1339386385}
  _lv1_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 0; x <= 180; x += 90) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv1.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  _lv1_countLatGrid (hemisphere) {
    for (let x = 0; x <= 180; x += 10) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 90) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv1.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  _lv2_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 90; x <= 180; x += 45) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv2.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOWGREEN
          }
        }
      ))
    }
  }
  _lv2_countLatGrid (hemisphere) {
    for (let x = 90; x <= 180; x += 45) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv2.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOWGREEN
          }
        }
      ))
    }
    console.log('lv2', this.lineEntitiesLv2);
  }
  _lv3_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 90; x <= 135; x += 22.5) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv3.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv3_countLatGrid (hemisphere) {
    for (let x = 90; x <= 135; x += 22.5) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv3.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv3', this.lineEntitiesLv3);
  }
  _lv4_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 90; x <= 135; x += 11.25) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv4.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv4_countLatGrid (hemisphere) {
    for (let x = 90; x <= 135; x += 11.25) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv4.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv4', this.lineEntitiesLv4);
  }
  _lv5_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 90; x <= 135; x += 5.625) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv5.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  _lv5_countLatGrid (hemisphere) {
    for (let x = 90; x <= 135; x += 5.625) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv5.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
    console.log('lv5', this.lineEntitiesLv5);
  }
  _lv6_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 90; x <= 135; x += 2.8125) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv6.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  _lv6_countLatGrid (hemisphere) {
    for (let x = 90; x <= 135; x += 2.8125) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv6.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
    console.log('lv6', this.lineEntitiesLv6);
  }
  _lv7_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 90; x <= 123.75; x += 1.40625) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv7.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOWGREEN
          }
        }
      ))
    }
  }
  _lv7_countLatGrid (hemisphere) {
    for (let x = 90; x <= 123.75; x += 1.40625) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv7.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOWGREEN
          }
        }
      ))
    }
    console.log('lv7', this.lineEntitiesLv7);
  }
  _lv8_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 112.5; x <= 123.75; x += 0.703125) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv8.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOWGREEN
          }
        }
      ))
    }
  }
  _lv8_countLatGrid (hemisphere) {
    for (let x = 112.5; x <= 123.75; x += 0.703125) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv8.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOWGREEN
          }
        }
      ))
    }
    console.log('lv8', this.lineEntitiesLv8);
  }
  _lv9_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 112.5; x <= 121.25; x += 0.3515625) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv9.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
  }
  _lv9_countLatGrid (hemisphere) {
    for (let x = 112.5; x <= 121.25; x += 0.3515625) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv9.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
    console.log('lv9', this.lineEntitiesLv9);
  }
  _lv10_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.17578125) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv10.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.RED
          }
        }
      ))
    }
  }
  _lv10_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.17578125) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv10.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.RED
          }
        }
      ))
    }
    console.log('lv10', this.lineEntitiesLv10);
  }
  _lv11_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.087890625) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv11.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv11_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.087890625) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv11.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv11', this.lineEntitiesLv11);
  }
  _lv12_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.0439453125) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv12.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv12_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.0439453125) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv12.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv12', this.lineEntitiesLv12);
  }
  _lv13_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.02197265625) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv13.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv13_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.02197265625) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv13.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv13', this.lineEntitiesLv13);
  }
  _lv14_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.010986328125) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv14.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv14_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.010986328125) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv14.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv14', this.lineEntitiesLv14);
  }
  _lv15_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.0054931640625) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv15.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv15_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.0054931640625) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv15.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv15', this.lineEntitiesLv15);
  }
  _lv16_countLonGrid (hemisphere) {
    for (let y = 0; y <= 66; y += 10) {
      let positionsX = [];
      for (let x = 115.3125; x <= 118.4375; x += 0.00274658203125) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this.lineEntitiesLv16.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsX,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
  }
  _lv16_countLatGrid (hemisphere) {
    for (let x = 115.3125; x <= 118.4375; x += 0.00274658203125) {
      let positionsY = [];
      for (let y = 0; y <= 66; y += 10) {
        const pos = Cesium.Cartesian3.fromDegrees(x, y)
        if (hemisphere[0] !== 'N') {
          pos.z = -pos.z
        }
        if (hemisphere[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsY.push(pos)
      }
      this.lineEntitiesLv16.push(this.viewer.entities.add(
        {
          polyline: {
            positions: positionsY,
            width: 1,
            material: Cesium.Color.YELLOW
          }
        }
      ))
    }
    console.log('lv16', this.lineEntitiesLv16);
  }
  indexOfLonLatGrid (codeArr, CColor = Cesium.Color.BLUE) {
    const gindex = codeArr[4] || '0'
    const dxLon = this.mapCfg[codeArr[2]][2][1][0]
    const dxLat = this.mapCfg[codeArr[2]][2][1][1]
    const dxHig = this.mapCfg[codeArr[2]][2][1][2]

    const dxNum = this.mapCfg[codeArr[2]][2][2][0]
    const minLon = this.mapCfg[codeArr[2]][0][gindex][0] + dxLon * codeArr[3][0]
    const minLat = this.mapCfg[codeArr[2]][0][gindex][2] + dxLat * codeArr[3][1]

    const obj = {}
    // 经度
    for (let y = minLat; y <= minLat + dxLat + dxNum; y += dxNum) {
      let positionsX = [];
      for (let x = minLon; x <= minLon + dxLon + dxNum; x += dxNum) {
        const pos = this[`GJson_${codeArr[2]}_${codeArr[3][2]}_${gindex}`][`${x.toFixed(6)}|${y.toFixed(6)}|0`]
        // const pos =Cesium.Cartesian3.fromDegrees(x.toFixed(6) * 1, y.toFixed(6) * 1, 0)
        // obj[`${x.toFixed(6)}|${y.toFixed(6)}|0`] = pos

        // const pos1 = Cesium.Cartesian3.fromDegrees(x.toFixed(6) * 1, y.toFixed(6) * 1, this.mapCfg[codeArr[2]][1])
        // obj[`${x.toFixed(6)}|${y.toFixed(6)}|0`] = pos1
        if (codeArr[0] !== 'N') {
          pos.z = -pos.z
        }
        if (codeArr[1] !== 'E') {
          pos.y = -pos.y
        }
        positionsX.push(pos)
      }
      this[`lineEntitiesLv${codeArr[2]}`].push(
        this.viewer.entities.add({
          name: `LV${codeArr[2]}|Lon:${minLon}-${minLon + dxLon}|Lat:${minLat}-${minLat + dxLat}(${y})|${codeArr[3]}`,
          polyline: { positions: positionsX, width: 1, material: CColor }
        }))
    }
    // 纬度
    // for (let x = minLon; x <= minLon + dxLon + dxNum; x += dxNum) {
    //   let positionsY = [];
    //   for (let y = minLat; y <= minLat + dxLat + dxNum; y += dxNum) {
    //     const pos = this[`GJson_${codeArr[2]}_${codeArr[3][2]}_${gindex}`][`${x.toFixed(6)}|${y.toFixed(6)}|0`]
    //     if (codeArr[0] !== 'N') {
    //       pos.z = -pos.z
    //     }
    //     if (codeArr[1] !== 'E') {
    //       pos.y = -pos.y
    //     }
    //     positionsY.push(pos)
    //   }
    //   this[`lineEntitiesLv${codeArr[2]}`].push(this.viewer.entities.add(
    //     {
    //       name: `LV${codeArr[2]}|Lon:${minLon}-${minLon + dxLon}(${x})|Lat:${minLat}-${minLat + dxLat}|${codeArr[3]}`,
    //       polyline: {
    //         positions: positionsY,
    //         width: 1,
    //         material: CColor
    //       }
    //     }
    //   ))
    // }

    // 高度
    console.log(obj);
    const arr1 = Object.values(this[`GJson_${codeArr[2]}_${codeArr[3][2]}_${gindex}`])
    const arr2 = Object.values(this[`GJson_${codeArr[2]}_${codeArr[3][2] + 1}_${gindex}`])
    for (let index = 0; index < arr1.length; index++) {
      let arr3 = []
      arr3.push(arr1[index], arr2[index])
      this[`lineEntitiesLv${codeArr[2]}`].push(this.viewer.entities.add(
        {
          name: `LV${codeArr[2]}|`,
          polyline: {
            positions: arr3,
            width: 1,
            material: Cesium.Color.BLUE
          }
        }
      ))
    }
    console.log(arr1.length, arr2.length);
  }
  _showGrid (isShow) {
    this[`lineEntitiesLv${this.Level}`].forEach(element => {
      element.show = isShow
    });
  }
  showGridByZoom (zoom) {
    this.Level = zoom
    this.lineLvArr.forEach((element, index) => {
      if (index === zoom) {
        element.forEach(item => {
          item.show = true
        })
      } else {
        element.forEach(item => {
          item.show = false
        })
      }
    })
  }
  _setLevel (num) {
    console.log('_setLevel->', num);
    let str = 0
    switch (num) {
      case 1:
        str = 1
        break;
      case 2:
        str = 2
        break;
      case 3:
        str = 3
        break;
      case 4:
        str = 4
        break;
      case 5:
        str = 5
        break;
      case 6:
        str = 6
        break;
      case 7:
        str = 7
        break;
      case 8:
        str = 8
        break;
      case 9:
        str = 9
        break;
      case 10:
        str = 10
        break;
      case 11:
        str = 11
        break;
      case 12:
        str = 12
        break;
      case 13:
        str = 13
        break;
      case 14:
        str = 14
        break;
      case 15:
        str = 15
        break;
      case 16:
        str = 16
        break;
      case 17:
        str = 16
        break;
      case 18:
        str = 16
        break;
      case 19:
        str = 16
        break;
      default:
        str = 16
        break;
    }
    this.showGridByZoom(str)
  }
}

export default SpaceGridClass;    